package cn.cqone.crm.service.impl;

import cn.cqone.crm.mapper.BaseMapper;
import cn.cqone.crm.service.BaseService;
import cn.cqone.crm.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

@Transactional
public class BaseServiceImpl<T,ID extends Serializable,Q> implements BaseService<T,ID,Q> {

    @Autowired
    private BaseMapper<T,ID,Q> baseMapper;

    @Override
    public int add(T obj) {
        return baseMapper.add(obj);
    }

    @Override
    public int update(T obj) {
        return baseMapper.update(obj);
    }

    @Override
    public int delete(ID id) {
        return baseMapper.delete(id);
    }

    @Override
    public void batchDelete(List<Long> ids) {
        baseMapper.batchDelete(ids);
    }

    @Override
    public T findById(ID id) {
        return baseMapper.findById(id);
    }

    @Override
    public List<T> findAll() {
        return baseMapper.findAll();
    }

    @Override
    public Integer findCount(Q query) {
        return baseMapper.findCount(query);
    }

    @Override
    public List<T> findList(Q query) {
        return baseMapper.findList(query);
    }

    @Override
    public PageList<T> findByPage(Q query) {
        Integer total = baseMapper.findCount(query);
        if(total==0){
            return new PageList<>();
        }
        List<T> list = baseMapper.findList(query);

        return new PageList<>(total,list);
    }
}
